package com.zhiyou.serviceimpl;

import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou.mapper.TeacherManageMapper;
import com.zhiyou.model.FYStudyAttendance;
import com.zhiyou.model.FyClass;
import com.zhiyou.service.TeacherManageService;

@Service("TeacherService")
public class TeacherServiceImpl implements TeacherManageService {
	@Autowired
	TeacherManageMapper teacherManageMapper;

	// 获取班级ID,以及时间,以及显示全部学生的考勤的次数
	public List<FyClass> SelectByClassTID(Integer class_id, Integer year, Integer month) {
		return teacherManageMapper.SelectByClassTID(class_id, year, month);
	}

	// 根据学生ID显示考勤信息
	public List<Map<String, String>> SelectByStudent(Integer class_id, Integer year, Integer month) {
		return teacherManageMapper.SelectByStudent(class_id, year, month);
	}

	// 根据学生姓名进行模糊查询
	public List<Map<String, String>> selectByStudentName(String student_name) {
		return teacherManageMapper.selectByStudentName(student_name);
	}

	// 这是查学生考勤状况的
	@Override
	public List<Map<String, String>> SelectByStudentId(Integer student_id, Integer year, Integer month) {
		return teacherManageMapper.SelectByStudentId(student_id, year, month);
	}

	// 这是时间判断
	@Override
	public List<FYStudyAttendance> SelectByStudentIdTwo(Integer student_id, Integer year, Integer month) {
		List<FYStudyAttendance> list = teacherManageMapper.SelectByStudentIdTwo(student_id, year, month);
		SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
		try {
			java.util.Date dateone =format.parse("8:30:00");
			java.util.Date datetwo = format.parse("18:30:00");
			for (FYStudyAttendance fy : list) {
				if (fy.getLeave_or_not() != 1) {
					if (fy.getArrive_time().getTime() > dateone.getTime()) {
						fy.setIs_be_late(1);
						if (fy.getLeave_time().getTime() > datetwo.getTime()) {
							fy.setIs_leave_early(1);
						}
					}
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	//请假添加
	@Override
	public void addone(Integer student_id, Timestamp vacate_commit_time) {
		DateFormat df=new SimpleDateFormat("HH:mm:ss");
		DateFormat dfs=new SimpleDateFormat("yyyy-MM-dd");
		String date=df.format(vacate_commit_time);
		String dateone=dfs.format(vacate_commit_time);
		System.out.println("我是第一个"+date);
		System.out.println("我是第二个"+dateone);
		try {
			java.util.Date date2=df.parse(date);
			Time time=new Time(date2.getTime());
			Date date4 = Date.valueOf(dateone);
			FYStudyAttendance fyStudyAttendance = new FYStudyAttendance(student_id, 4, date4,time, 1);
			System.out.println(fyStudyAttendance);
			teacherManageMapper.add(fyStudyAttendance);
		} catch (Exception e) {
			
			
			
			
			e.printStackTrace();
		}
				
	}

	@Override
	public void add(FYStudyAttendance fyStudyAttendance) {
		teacherManageMapper.add(fyStudyAttendance);
	}

	@Override
	public void updateManage(FYStudyAttendance fyStudyAttendance) {
		teacherManageMapper.update(fyStudyAttendance);
	}

	
	@Override
	public List<Map<String, String>> selectCheckSum(Integer class_id) {
		List<Map<String,String>> selectSums= teacherManageMapper.SelectSum(class_id);
		List<Map<String,String>>selectNor=teacherManageMapper.SelectNCheck(class_id);
		selectSums.addAll(selectNor);
		return selectSums;
	}

	//这里是智慧班牌调用的考勤记录主页面
	@Override
	public List<Map<String, String>> SelectUnify(Integer id, Integer class_id) {
	
		if (id == 1) {
			return teacherManageMapper.SelectTure(class_id);
		} 
		return teacherManageMapper.SelectFalse(class_id);
		}

	@Override
	public List<Map<String, String>> SelectMHCX(Integer id, Integer class_id, String student_name) {
		if (id == 1) {
			return teacherManageMapper.SelectMHOne(class_id, student_name);
		}
		return teacherManageMapper.SelectMHTwo(class_id, student_name);
	}

	


}
